<!doctype html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>

<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<html>
<head>
<meta charset="utf-8">
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/easyui.css">
<script src="${basePath }commonJs/jquery.min.js"></script>
<script src="${basePath }commonJs/jquery.easyui.min.js"></script>
<script src="${basePath }commonJs/jt_normal.js"></script>
<script src="${basePath }commonJs/jt_select.js"></script>
<script src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>

<script src="${basePath }commonJs/promotion/wolf_common.js"></script>
<script src="${basePath }commonJs/promotion/wolf_validation.js"></script>
<title>房间管理</title>
</head>

<script type="text/javascript">
var userAll = ${userAll};
var batchId = "${batchId}";
var condList=[];
/***
 * 	 =1 会员
	 =2 非会员
	 =3 访客
	 =4 派对联系人
	 =5 团体联系人
 */
var bat = {
		"srcType":1,
		"batchCond":{
			"e1":{
				"status":"",
				"hysr":"",
				"rhsr":"",
				"sxsr":"",
				"glxs":""
			},
			"a2":{
				"f_fhysr":"",
				"f_gprq":""
			},
			"b3":{
				"fw_fwrq":"",
				"fw_glxs":""
			},
			"c4":{
				"qbrq":""
			},
			"5":{
				
			}
		},
		"outbox":[]
};
$(document).ready(function(){
	/**初始化数据*/
	bat.srcType=1;
	refSale("glxs");
	refSale("fw_glxs");
	
	/**编辑时 初始化数据*/
	editLoad();
	
	batch_li();
	
	/**编辑抽样数量*/
	readTime(batchId);
});
/**
 * 关联销售 绑定select标签
 */
function refSale(selectId){
	$("#"+selectId).empty();
	$("#"+selectId).append("<option value=''>全部</option>");
	if(wolf.isNotNull(userAll) && userAll.length > 0){
		wolf.data_foreach(userAll, function(i,user){
			var option = "<option value='"+user.pkUsrId+"'>"+user.usrName+"</option>";
			$("#"+selectId).append(option);
		});
	}
	refreshSelect();
}
/**编辑加载内容*/
function editLoad(){
	if(wolf.isNotNull(condList) && condList.length > 0){
		bat.srcType=1;
		var _flag = 0;
		wolf.data_foreach(condList, function(i,obj){
			var objContext = obj.condDetail;
			
			if(/* wolf.isNotNull(objContext) */wolf.isNotNull(obj.profileType)){
				var contextArry = objContext.split("|");
				
				/* if(wolf.isNotNull(contextArry) && contextArry.length > 0){ */
					
					if(obj.profileType == 1){
						bat.batchCond.e1.status = contextArry[0];
						$("#status").val(contextArry[0]);
						wolf.option_selected("status",contextArry[0]);
						
						
						bat.batchCond.e1.hysr = isSplit(contextArry[1],",",0)+","+isSplit(contextArry[1],",",1);
						$("#hysr1").val(isSplit(contextArry[1],",",0));
						$("#hysr2").val(isSplit(contextArry[1],",",1));
						
						bat.batchCond.e1.rhsr = isSplit(contextArry[2],",",0)+","+isSplit(contextArry[2],",",1);
						$("#rhsr1").val(isSplit(contextArry[2],",",0));
						$("#rhsr2").val(isSplit(contextArry[2],",",1));
						
						bat.batchCond.e1.sxsr = isSplit(contextArry[3],",",0)+","+isSplit(contextArry[3],",",1);
						$("#sxsr1").val(isSplit(contextArry[3],",",0));
						$("#sxsr2").val(isSplit(contextArry[3],",",1));
						
						bat.batchCond.e1.glxs = contextArry[4];
						$("#glxs").val(contextArry[4]);
						wolf.option_selected("glxs",contextArry[4]);
						
						e1();
						abs_check_box(1);
						_flag ++;
					}else if(obj.profileType == 2){
						bat.batchCond.a2.f_fhysr = isSplit(contextArry[0],",",0)+","+isSplit(contextArry[0],",",1);
						$("#f_fhysr1").val(isSplit(contextArry[0],",",0));
						$("#f_fhysr2").val(isSplit(contextArry[0],",",1));
						
						bat.batchCond.a2.f_gprq = isSplit(contextArry[1],",",0)+","+isSplit(contextArry[1],",",1);
						$("#f_gprq1").val(isSplit(contextArry[1],",",0));
						$("#f_gprq2").val(isSplit(contextArry[1],",",1));
						
						a2();
						abs_check_box(2);
						_flag ++;
					}else if(obj.profileType == 3){
						bat.batchCond.b3.fw_fwrq = isSplit(contextArry[0],",",0)+","+isSplit(contextArry[0],",",1);
						$("#fw_fwrq1").val(isSplit(contextArry[0],",",0));
						$("#fw_fwrq2").val(isSplit(contextArry[0],",",1));
						
						bat.batchCond.b3.fw_glxs = contextArry[1];
						$("#fw_glxs").val(contextArry[1]);
						
						wolf.option_selected("fw_glxs",contextArry[4]);
						
						b3();
						abs_check_box(3);
						_flag ++;
					}else if(obj.profileType == 4){
						bat.batchCond.c4.qbrq = isSplit(contextArry[0],",",0)+","+isSplit(contextArry[0],",",1);
						$("#qbrq1").val(isSplit(contextArry[0],",",0));
						$("#qbrq2").val(isSplit(contextArry[0],",",1));
						
						c4();
						abs_check_box(4);
						_flag ++;
					}
				/* } */
				
			}
		});
		$("#abs_checkbox").attr("checked",(_flag==4?true:false));
	}else if(wolf.isNotNull(batchId)){
		bat.srcType=2;
		dPage();
	}
}

function abs_check_box(value){
	$("input[name='abs_checkbox1']").each(function(){
		var ck = $(this).val();
		if(ck == value){
			$(this).attr("checked",true); 
		}
	});
}

/**分割字符串*/
function isSplit(context,spes,index){
	if(wolf.isNotNull(context)){
		var arry = context.split(spes);
		var leng = arry.length;
		if(wolf.isNotNull(arry) && leng > 0){
			var i = (index >= leng?index-1:index);
			return arry[i];
		}else{
			return "";
		}
	}
	return "";
}
/***
 * 验证内容
 */
function isValidation(){
	wolf_v.v_bean.formId="batch_form";
	wolf_v.v_bean.alertType="5";
	wolf_v.v_bean.alertTypeCall=validation_Call;
	wolf_v.v_validation();
	return wolf_v.v_check_result;
}
function validation_Call(i,array){
	if(i == -1){
		if(wolf.isNotNull(array) && array.length > 0){
			var obj = array[0];
			alertInfo(obj.t.replace("&p",obj.d));
		}
	}
}



/**选择发送条件*/
function batche_where(t){
	if(isValidation()){
		if(bat != null){
			bat.srcType=t;
		}else{
			bat = {
				"srcType":t
			};
		}
	}
	batch_li();
}
function batch_li(){
	var t = bat.srcType;
	
	if(t ==1 ){
		$("#_v1").attr("checked",true); 
		$("#_v2").attr("checked",false); 
		
		$("#_v1v").show();
		$("#_v2v").hide();
		$("#form_phone_page").hide();
	}else{
		$("#_v2").attr("checked",true); 
		$("#_v1").attr("checked",false); 
		
		$("#_v1v").hide();
		$("#_v2v").show();
		$("#form_phone_page").show();
	}
}

/**提交数据*/
function submit_v(sta){
	var ms = (sta == 2 ? '提交':'保存');
	var flag = false ; 
	$.messager.confirm('提示', '你确定要'+ms+'吗?', function(r) {
		if(r){
			
			if(!isValidation()){
				return;
			}
			var t = bat.srcType;
			var url="";
			var param = "status="+(sta>10?1:sta)+"&srcType="+t+"&context="+$("#b_contText").val()+
						"&planTimeStr="+$("#date1").val()+"&fkBranId="+$("#fkBranId_").val()+"&pkBatchId="+batchId;
			
			/**获取抽样条件*/
			
			if(t == 1){
				var index_val = 0;
				var checkboxs = getAbsCheckBox();
				var sb = "";
				if(wolf.isNotNull(checkboxs)){
					
					sb += (checkboxs.indexOf("1") > -1)? "&condList["+index_val+"].profileType=1&condList["+(index_val++)+"].condDetail="+bat.batchCond.e1.status + "|" + 
															bat.batchCond.e1.hysr + "|" + 
															bat.batchCond.e1.rhsr + "|" + 
															bat.batchCond.e1.sxsr + "|" + 
															bat.batchCond.e1.glxs :"";
					sb += (checkboxs.indexOf("2") > -1)?"&condList["+index_val+"].profileType=2&condList["+(index_val++)+"].condDetail="+bat.batchCond.a2.f_fhysr + "|" + 
							bat.batchCond.a2.f_gprq :"" ;
					sb += (checkboxs.indexOf("3") > -1)? "&condList["+index_val+"].profileType=3&condList["+(index_val++)+"].condDetail="+bat.batchCond.b3.fw_fwrq + "|" + 
							bat.batchCond.b3.fw_glxs :"";
					sb += (checkboxs.indexOf("4") > -1)? "&condList["+index_val+"].profileType=4&condList["+(index_val++)+"].condDetail="+bat.batchCond.c4.qbrq:"" ;
					
					param += sb; 
				}
				
			}else if(t == 2){
				param += "&phoneList="+bat.outbox.toString();
			}
			
			/**编辑数据*/
			if(wolf.isNotNull(batchId)){
				url="${basePath }sms/batch/updateBatch.shtml";
			/**添加数据*/
			}else{
				url="${basePath }sms/batch/addBatch.shtml";
			}
			$.ajax({ 
				url: url,
				data:param,
				async:false,
				dataType: 'json',
				type:'POST',
				success: function(data){
					if(wolf.isNotNull(data)){
						batchId = data.pkBatchId;
						bat.outbox=[];
						if(sta == 2 || sta == 3 || sta > 10){
							window.location.href='${basePath}sms/batch/home.shtml';
						}else{
							readTime(batchId);
						}
					}else{
						alertInfo("处理数据错误，请刷新重试！");
					}
		      	}
			});
	
		flag = true;
		}
	});
	
}
function readTime(batchId){
	if(wolf.isNotNull(batchId)){
		$.ajax({ 
			url: "${basePath}sms/batch/readTimeCount.shtml",
			data:"fkBatchId="+batchId,
			async:false,
			dataType: 'json',
			type:'POST',
			success: function(data){
				$("#_batch_cond").text("");
				$("#_batch_cond").text("预计发送个数为："+data);
	      	}
		});
	}else{
		$("#_batch_cond").text("");
		$("#_batch_cond").text("预计发送数量：请先保存后查看数量");
	}
	
}
function check_readTime(){
	if(wolf.isNotNull(batchId)){
		submit_v(1);
	}
}

</script>
<c:if test="${!empty condList }">
	<script type="text/javascript">
		condList =${condList};
	</script>
</c:if>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    	
    		<shiro:hasPermission name="sms/batch/home.shtml">
            	<li class="content_hover"><a href="${basePath}sms/batch/home.shtml"><i class="nav_icon_v"></i><br>短信发送</a></li>
        	</shiro:hasPermission>
        
        </ul>
    </div>
    <div class="content_r mt10">
    	<!---- 内容 --->
    	
        <div class="file_single_dl fixed mt20">
        	<form action="#" id="batch_form">
	        	<dl class=" w370 fl">
	            	<dd><label>所属门店：</label>
	                	<div class="uboxstyle">
	                        <select name="fkBranId_" id="fkBranId_" data_v="not_empty" data_v_info="所属门店">
	                      		<c:forEach items="${branAll }" var="bran" varStatus="cc">
	                           		<c:choose>
	                            		<c:when test="${branId == 'ZB' }">
	                            			<c:if test="${bran.pkBranId !='ZB'}">
	                            				<option value="${bran.pkBranId}">${bran.branName }</option>
	                            			</c:if>
		                            	</c:when>
		                            	<c:when test="${branId != 'ZB' && branId ==bran.pkBranId }">
		                            		
		                            		<option value="${bran.pkBranId}">${bran.branName }</option>
		                            	</c:when>
		                            	
                            		</c:choose>
	                           </c:forEach>
		                     </select>
	                    </div>
	                </dd>
	                <dd><label>发送内容：</label>
		                <input type="button" class="btn" value="模板" onclick="seacheTemp()"><input type="button" class="btn ml10" value="保存为模板" onclick="javascript:$('#_tempContext').val($('#b_contText').val());$('#f').window('open')">
	                </dd>
	            	<dd><label>发送内容：</label><textarea class="textare w200 h100" id="b_contText" name="b_contText" data_v="not_empty" data_v_info="发送内容">${entity.context }</textarea></dd>
	                <dd><label>预期发送时间：</label><input  type="text" name="date1" id="date1" data_v="not_empty" data_v_info="预期发送时间" value="${entity.planTimeStr == null ? currentTime: entity.planTimeStr}"
						onClick="WdatePicker({minDate: '%y-%M-%d %H:%m:%s' ,dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate: true,isShowWeek:true,isShowClear:true,readOnly:true})"
						class="Wdate iput_t w200" readonly /></dd>
	            </dl>
            </form>
            <div class="duax_x ml30">
                <ul class="ul_radio fixed" >
                    <li><input type="radio" class="mr5" name="vv" id="_v1" value="1" checked onclick="batche_where(1)"> 现有档案中抽取</li>
                    <li><input type="radio" class="mr5" name="vv" id="_v2" value="2"  onclick="batche_where(2)">手工录入</li>
                </ul>
                <ul>
                    <li id="_v1v">
                    	<table class="table">
                        	<tr>
                        		<th><input type="checkbox" id="abs_checkbox" name="abs_checkbox" class="mr5" onclick="javascript:wolf.checkLikeSelected('abs_checkbox', 'abs_checkbox1');check_readTime();"></th>
                                <th>档案类型</th>
                                <th>抽取条件</th>
                            </tr>
                            <tr>
                            	<td><input type="checkbox" class="mr5" id="abs_checkbox1" name="abs_checkbox1" value="1" onclick="javascript:check_readTime();"></td>
                            	<td>会员</td>
                                <td class="lv"><a href="#" onclick="javascript:if(isValidation()){$('#e').window('open')}" id="e1_h" >无</a></td>
                            </tr>
                            <tr>
                            	<td><input type="checkbox" class="mr5" id="abs_checkbox1" name="abs_checkbox1"  value="2" onclick="javascript:check_readTime();"></td>
                            	<td>非会员</td>
                                <td class="lv"><a href="#" onclick="javascript:if(isValidation()){$('#a').window('open')}" id="a2_h">无</a></td>
                            </tr>
                            <tr>
                            	<td><input type="checkbox" class="mr5" id="abs_checkbox1" name="abs_checkbox1" value="3" onclick="javascript:check_readTime();"></td>
                            	<td>访客</td>
                                <td class="lv"><a href="#" onclick="javascript:if(isValidation()){$('#b').window('open')}"  id="b3_h">无</a></td>
                            </tr>
                            <tr>
                            	<td><input type="checkbox" class="mr5" id="abs_checkbox1" name="abs_checkbox1" value="4" onclick="javascript:check_readTime();"></td>
                            	<td>派对联系人</td>
                                <td class="lv"><a href="#" onclick="javascript:if(isValidation()){$('#c').window('open')}"  id="c4_h">无</a></td>
                            </tr>
                        </table>
                        <!----翻页----->
                        <div class="page fr m10">
                        </div>
                        <!----翻页----->
                        <p class="m10" id="_batch_cond">预计发送数量：请先保存后查看数量</p>
                    </li>
                    <li id="_v2v">
                    	<table class="table" id="form_phone_table" >
                        	<tr>
                                <th>电话号码</th>
                                <th>操作</th>
                            </tr>
                            
                        </table>
                        <input type="button" class="btn mt10" value="增加" onclick="if(isValidation()){$('#d').window('open')}">
                        <!----翻页----->
                        <div class="page fr m10" id="form_phone_page">
                        </div>
                        <!----翻页----->
                        <p class="mt10" id="form_phone_count">发送数量：0</p>
                    </li>
                </ul>
        	</div>
        </div>
        <!----底部按钮----->
        <div class="btm_btn mt50">
                <dl>
                	<dd><input type="button" class="btn" value="保存" onclick="submit_v(11)"></dd>
                    <dd><input type="button" class="btn" value="提交" onclick="submit_v(2)"></dd>
                    <dd><input type="button" class="btn" value="返回" onclick="javascript:window.location.href='${basePath}sms/batch/home.shtml'"></dd>
                    <!-- <dd><input type="button" class="btn" value="关闭" onclick="submit_v(3)"></dd> -->
                </dl>
        </div>
        <!----底部按钮----->
        <!---- 内容 --->
    </div>
</div>

<!---弹出层--->
<script type="text/javascript">
function e1(){
	if(wolf.isNotNull(bat.batchCond)){
		if(!isDateNotNull($("#hysr1").val(),$("#hysr2").val())){
			alertInfo("请输入完整会员生日！");
			return ;
		}
		if(!isDateNotNull($("#rhsr1").val(),$("#rhsr2").val())){
			alertInfo("请输入完整入会日期！");
			return ;
		}
		if(!isDateNotNull($("#sxsr1").val(),$("#sxsr2").val())){
			alertInfo("请输入完整失效日期！");
			return ;
		}
		bat.batchCond.e1.status = $("#status").val();
		bat.batchCond.e1.hysr = $("#hysr1").val()+","+$("#hysr2").val();
		bat.batchCond.e1.rhsr = $("#rhsr1").val()+","+$("#rhsr2").val();
		bat.batchCond.e1.sxsr = $("#sxsr1").val()+","+$("#sxsr2").val();
		bat.batchCond.e1.glxs = $("#glxs").val();

		
		
		var status = $("#status").val();
		var _hysr = $("#hysr1").val()+"~"+$("#hysr2").val();
		var _rhsr = $("#rhsr1").val()+"~"+$("#rhsr2").val();
		var _sxsr = $("#sxsr1").val()+"~"+$("#sxsr2").val();
		var _glxs = $("#glxs").val();
		var showdiv = 
					wolf.isNotNull(status)?"状态:"+wolf.option_text("status", true)+"...":
					_hysr.length > 1?'生日:'+_hysr+"...":
					_rhsr.length > 1?'入会日期:'+_hysr+"...":
					_sxsr.length > 1?'失效日期:'+_hysr+"...":
					wolf.isNotNull(_glxs)?'销售:'+wolf.option_text("glxs", true)+"...":"无";
		$("#e1_h").text("");
		$("#e1_h").text(showdiv);
	}
	$('#e').window('close');
}
</script>
<div id="e" class="easyui-window" title="会员条件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:480px; height:400px; position:relative;">
	<ul class="ul_label w360_c pt20">
    	<li><label>会员状态：</label>
        	<div class="uboxstyle">
                <select name="status" id="status" >
                    <option value="">全部</option>
                    <option value="1">未激活</option>
                    <option value="2">有效 </option>
                    <option value="3">过期</option>
                    <option value="4">停卡 </option>
                    <option value="5">新建</option>
                    <!-- 1：未激活 2：有效  3：过期  4：停卡 5：新建 -->
                </select>
            </div>
        </li>
        <li><label>会员生日：</label>
        	<input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'hysr2\')}'})" class="Wdate iput_t w82" id="hysr1">
<span>至</span><input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'hysr1\')}'})" class="Wdate iput_t w82"  id="hysr2"></dd>
        </li>
        <li><label>入会日期：</label>
        	<input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'rhsr2\')}'})" class="Wdate iput_t w82" id="rhsr1">
<span>至</span><input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'rhsr1\')}'})" class="Wdate iput_t w82" id="rhsr2"></dd>
        </li>
        <li><label>失效日期：</label>
        	<input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'sxsr2\')}'})" class="Wdate iput_t w82" id="sxsr1">
<span>至</span><input type="text"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'sxsr1\')}'})" class="Wdate iput_t w82" id="sxsr2">
			</dd>
        </li>
        <li><label>关联销售：</label>
        	<div class="uboxstyle">
                <select name="glxs" id="glxs">
                	<option value="">全部</option>
                </select>
            </div>
        </li>
    </ul>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:e1();" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#e').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!---弹出层--->
<!---弹出层--->
<script type="text/javascript">
function a2(){
	if(wolf.isNotNull(bat.batchCond)){
		if(!isDateNotNull($("#f_fhysr1").val(),$("#f_fhysr2").val())){
			alertInfo("请输入完整非会员生日！");
			return ;
		}
		if(!isDateNotNull($("#f_gprq1").val(),$("#f_gprq2").val())){
			alertInfo("请输入完整购票日期！");
			return ;
		}
		bat.batchCond.a2.f_fhysr = $("#f_fhysr1").val()+","+$("#f_fhysr2").val();
		bat.batchCond.a2.f_gprq = $("#f_gprq1").val()+","+$("#f_gprq2").val();
		/* submit_v(1); */
		var _f_fhysr = $("#f_fhysr1").val()+"~"+$("#f_fhysr2").val();
		var _f_gprq = $("#f_gprq1").val()+"~"+$("#f_gprq2").val();
		
		var showdiv = 
			_f_fhysr.length > 1?'非会员生日:'+_f_fhysr+"...":
			_f_gprq.length > 1?'购票日期:'+_f_gprq+"...":"无";
		$("#a2_h").text("");
		$("#a2_h").text(showdiv);
		
	}
	$('#a').window('close');
}
</script>
<div id="a" class="easyui-window" title="非会员条件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:480px; height:320px; position:relative;">
	<ul class="ul_label w360_c pt20">
        <li><label>非会员生日：</label>
        	<input type="text" id="f_fhysr1" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'f_fhysr2\')}'})" class="Wdate iput_t w82">
<span>至</span><input type="text" id="f_fhysr2"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'f_fhysr1\')}'})" class="Wdate iput_t w82"></dd>
        </li>
        <li><label>购票日期：</label>
        	<input type="text" id="f_gprq1" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'f_gprq2\')}'})" class="Wdate iput_t w82">
<span>至</span><input type="text" id="f_gprq2" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'f_gprq1\')}'})" class="Wdate iput_t w82"></dd>
        </li>
    </ul>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:a2();" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#a').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!---弹出层--->
<!---弹出层--->
<script type="text/javascript">
function b3(){
	if(wolf.isNotNull(bat.batchCond)){
		if(!isDateNotNull($("#fw_fwrq1").val(),$("#fw_fwrq2").val())){
			alertInfo("请输入完整访客日期！");
			return ;
		}
		bat.batchCond.b3.fw_fwrq = $("#fw_fwrq1").val()+","+$("#fw_fwrq2").val();
		bat.batchCond.b3.fw_glxs = $("#fw_glxs").val();
		/* submit_v(1); */
		var _fw_fwrq = $("#fw_fwrq1").val()+"~"+$("#fw_fwrq2").val();
		var _fw_glxs = $("#fw_glxs").val();	
		var showdiv = 
			_fw_fwrq.length > 1?'访问日期:'+_fw_fwrq+"...":
			wolf.isNotNull(_fw_glxs)?'关联销售:'+wolf.option_text("fw_glxs", true)+"...":"无";
		$("#b3_h").text("");
		$("#b3_h").text(showdiv);
	}
	$('#b').window('close');
}
</script>
<div id="b" class="easyui-window" title="访客条件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:480px; height:320px; position:relative;">
	<ul class="ul_label w360_c pt20">
      <li><label>访问日期：</label>
        	<input type="text" id="fw_fwrq1" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'fw_fwrq2\')}'})" class="Wdate iput_t w82">
<span>至</span><input type="text" id="fw_fwrq2" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'fw_fwrq1\')}'})" class="Wdate iput_t w82"></dd>
        </li>
        <li><label>关联销售：</label>
        	<div class="uboxstyle">
                <select name="fw_glxs" id="fw_glxs">
                    <option>全部</option>
                    <option>选项</option>
                    <option>选项</option>
                    <option>选项</option>
                    <option>选项</option>
                </select>
            </div>
        </li>  
    </ul>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:b3();" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#b').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!---弹出层--->
<!---弹出层--->
<script type="text/javascript">
function c4(){
	if(wolf.isNotNull(bat.batchCond)){
		if(!isDateNotNull($("#qbrq1").val(),$("#qbrq2").val())){
			alertInfo("请输入完整派对日期！");
			return ;
		}
		bat.batchCond.c4.qbrq = $("#qbrq1").val()+","+$("#qbrq2").val();
		var _qbrq = $("#qbrq1").val()+"~"+$("#qbrq2").val();
		var showdiv =  _qbrq.length > 1?'举办日期:'+_qbrq+"...":"无";
		$("#c4_h").text("");
		$("#c4_h").text(showdiv);
		
	}
	$('#c').window('close');
}
</script>
<div id="c" class="easyui-window" title="派对团体条件" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:480px; height:320px; position:relative;">
	<ul class="ul_label w360_c pt20">
      <li><label>举办日期：</label>
        	<input type="text" id="qbrq1" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,maxDate:'#F{$dp.$D(\'qbrq2\')}'})" class="Wdate iput_t w82">
<span>至</span><input type="text" id="qbrq2"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true,minDate:'#F{$dp.$D(\'qbrq1\')}'})" class="Wdate iput_t w82"></dd>
        </li>
    </ul>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:c4();" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#c').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!---弹出层--->
<!---弹出层--->
<script type="text/javascript">
Array.prototype.contains = function (element) {
	  
    for (var i = 0; i < this.length; i++) {
        if (this[i] == element) {
            return true;
        }
    }
    return false;
}
function d(){
	var phones = $("#_d_").val();
	$("#_d_").val("");
	if(wolf.isNotNull(phones)){
		var pArry = phones.split("\n");/* phones.split(","); */
		if(wolf.isNotNull(pArry)){
			for(var i = 0 ; i < pArry.length ; i ++){
				var phone = pArry[i].replace(/[ ]/g,"");
				if(!d_mob(phone)){
					alertInfo("该手机号码格式不符:"+phone);
					$("#_d_").val(phones);
					return false;
				}
				if(!bat.outbox.contains(phone)){
					bat.outbox.push(phone);
				};
			};
		};
		submit_v(1);
		dPage();
	};
	return true;
}
function dPage(){
	
	$("#fkBatchId").val(batchId);
	var form = $("#form_phone_d"); 
    var pagebean = new PageBean(form);
    pagebean.setTableId("form_phone_table");
    pagebean.setCallback(dPageCall);
    pagebean.setFootId("form_phone_page");
    setPagebeanObj(pagebean); 
    pagebean.doPage();
    
    
}
function dPageCall(data,param){
	if(wolf.isNotNull(data)){
		wolf.data_foreach(data, function(i,obj){
			var tr = "<tr>"+
		                "<td>"+obj.destPhone+"</td>"+
		                "<td><input class=\"btn_l\" type=\"button\" onClick=\"d_delete('"+obj.pkSmsId+"')\" value=\"删除\"></td>"+
		           	 "</tr>";
		    $("#form_phone_table").append(tr);
		});
	};
	/**显示分页数量*/
    $("#form_phone_count").text("");
    $("#form_phone_count").text("发送数量:"+param.totalRecord);
}
function d_delete(smsid){
	$.messager.confirm('提示', '你确定要删除吗?', function(r) {
		if (r) {
			$.ajax({ 
				url: "${basePath }sms/batch/deleteSmsBox.shtml",
				data:"fkBatchId="+batchId+"&pkSmsId="+smsid,
				async:false,
				dataType: 'json',
				type:'POST',
				success: function(data){
					dPage();
		      	}
			});
		}
		
	});
	
}
function d_mob(str){
	re = /^1\d{10}$/;
    if (re.test(str)) {
        return true;
    } else {
    	return false;
    }
}
</script>
<div id="d" class="easyui-window" title="增加号码" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:360px; height:350px; position:relative;">
	<br>
	<label style="color: red; font-size: 15px">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		样例：多个手机号码之间用<*回车*>分割
	</label>
	<textarea class="h200 textare m30" style="width:280px;" id="_d_"></textarea> 
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:if(d()){$('#d').window('close');}" value="确定"></dd>
            <dd><input type="button" class="btn"  onclick="$('#d').window('close')" value="返回"></dd>
        </dl>
    </div>
    <form action="${basePath }sms/batch/searchSmsBox.shtml" id="form_phone_d">
    	<input type="hidden" name="fkBatchId" id="fkBatchId" value="">
    	<input type="hidden" name="pageNo" value="1">
    	<input type="hidden" name="pageSize" value="5">
    </form>
</div>
<!---弹出层--->
<script type="text/javascript">
/**操作模板*/
function seacheTemp(){
	$('#g').window('open');
	var form = $("#seacheTemp_form"); 
    var pagebean = new PageBean(form);
    pagebean.setTableId("seacheTemp_table");
    pagebean.setCallback(seacheTempCall);
    pagebean.setFootId("seacheTempl_page");
    setPagebeanObj(pagebean); 
    pagebean.doPage();
}
function seacheTempCall(data){
	if(wolf.isNotNull(data)){
		wolf.data_foreach(data, function(i,temp){
 			var tempId = temp.pkSmsContId;
 			var tmpName = (temp.tmplName.length>5?temp.tmplName.substr(0,5)+"...":temp.tmplName);
 			var tmpContext = ((temp.contText.length > 15)?temp.contText.substr(0,15)+"...":temp.contText);
			var tr = "<tr>"+
			        	"<td><input type=\"radio\" name='contTemp' value='"+tempId+"' onclick=\"templOnclick('"+tempId+"','"+temp.tmplName+"','"+tempId+"')\"></td>"+
			            "<td >"+temp.branName+"</td>"+
			            "<td class=\"lv\" title='"+temp.tmplName+"'><a href=\"#\" onclick=\"seacheByTemp('"+tempId+"')\">"+tmpName+"</a></td>"+
			            "<td title='"+temp.contText+"' id='td_"+tempId+"'>"+tmpContext+"</td>"+
			            "<td><input type=\"button\" class=\"btn_l\" value=\"删除\" onclick=\"delTempl('"+tempId+"')\"></td>"+
			        "</tr>";
		    $("#seacheTemp_table").append(tr);
		});
	}
}
/**查询短信模板*/
function seacheByTemp(tempId){
	$.ajax({ 
		url: "${basePath }sms/batch/seacheTempl.shtml",
		data:"pkSmsContId=" + tempId,
		async:false,
		dataType: 'json',
		type:'POST',
		success: function(data){
			var obj = data.results;
			if(wolf.isNotNull(obj) && obj.length == 1){
				
				$('#f').window('open');
				$("#_tempName").val(obj[0].tmplName);
				$("#_tempContext").val(obj[0].contText);
				$("#_tempId").val(obj[0].pkSmsContId);
			}
      	}
	});
}

function delTempl(templId){
	$.messager.confirm('提示', '你确定要删除吗?', function(r) {
		if (r) {
			$.ajax({ 
				url: "${basePath }sms/batch/templDel.shtml",
				data:"pkSmsContId=" + templId,
				dataType: 'json',
				type:'POST',
				success: function(data){
					seacheTemp();
		      	}
			});
		}
	});
}
/***
 * 选中  模板
 */
function templOnclick(id,name,context){
	var context = $("#td_"+	context).attr("title");
	$("#b_contText").val(context);
	$("#_tempId").val("");
}
function templClear(){
	$("#_tempName").val("");
	$("#_tempContext").val("");
	$("#_tempId").val("");
}

function editTempl(){
	var templId = $("#_tempId").val();
	if(wolf.isNull(templId)){
		addTempl();
		return;
	}
	$.ajax({ 
		url: "${basePath }sms/batch/templEdit.shtml",
		data:"pkSmsContId=" + templId+"&tmplName="+$("#_tempName").val()+"&contText="+$("#_tempContext").val()+"&tmplFlag=1&fkBranId="+$("#fkBranId_").val(),
		dataType: 'json',
		type:'POST',
		success: function(data){
			$('#f').window('close');
			seacheTemp();
      	}
	});
}
function addTempl(){
	$.ajax({ 
		url: "${basePath }sms/batch/templAdd.shtml",
		data:"tmplName="+$("#_tempName").val()+"&contText="+$("#_tempContext").val()+"&tmplFlag=1&fkBranId="+$("#fkBranId_").val(),
		dataType: 'json',
		type:'POST',
		success: function(data){
			alertInfo($common_create_success);
			$('#f').window('close');
      	}
	});
}



</script>

<!---弹出层--->
<div id="g" class="easyui-window" title="短信模板" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:650px; height:550px; position:relative;">
	<form action="${basePath }sms/batch/seacheTempl.shtml" id="seacheTemp_form">
		<ul class="ul_label w360_c pt20">
	        <li><label>所属门店：</label>
	        	<div class="uboxstyle">
	                <select name="fkBranId" id="fkBranId">
	            		<c:forEach items="${branAll }" var="bran" varStatus="cc">
		                 	<c:choose>
	                            		<c:when test="${branId == 'ZB' }">
	                            			<c:if test="${bran.pkBranId !='ZB'}">
	                            				<option value="${bran.pkBranId}">${bran.branName }</option>
	                            			</c:if>
		                            	</c:when>
		                            	<c:when test="${branId != 'ZB' && branId ==bran.pkBranId }">
		                            		
		                            		<option value="${bran.pkBranId}">${bran.branName }</option>
		                            	</c:when>
		                            	
                            		</c:choose>
	                 </c:forEach>
	             </select>
	            </div>
	        </li>
	        <li><label>模板名称：</label><input type="text" class="iput_t w200" name="tmplName"></li>
	        <li><label class="vt">内容：</label><textarea class="textare w200" name="contText"></textarea></li>
	        <li><label></label>
	        	<input type="button" class="btn mt10" value="查询" onclick="seacheTemp()">
	        	</li>
	    </ul>
	    <input type="hidden" name="tmplFlag" value="1">
	    <input type="hidden" name="pageNo" value="1">
	    <input type="hidden" name="pageSize" value="5">
	    
    </form>
    <div class="m10">
    <table class="table" id="seacheTemp_table">
    	<tr>
        	<th>选择</th>
            <th>所属门店</th>
            <th>模板名称</th>
            <th>内容</th>
            <th>操作</th>
        </tr>
    </table>
    <!----翻页----->
    <div class="page fr m10" id="seacheTempl_page">
    </div>
    <!----翻页----->
    </div>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="javascript:templClear();$('#g').window('close')" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#g').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!---弹出层--->

<!---弹出层--->
<div id="f" class="easyui-window" title="短信模板" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:430px; height:350px; position:relative;">
	<ul class="ul_label w360_c pt20">
		<li><label>模板名称：</label><input type="text" class="iput_t w200" name="tempName" id="_tempName"></li>
        <li><label class="vt">内容：</label><textarea class="textare w200" style="height: 150px" name="tempContext" id="_tempContext"></textarea></li>
    </ul>
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="editTempl()" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#f').window('close')" value="返回"></dd>
        </dl>
    </div>
    <input type="hidden" id="_tempId" value=""> 
</div>
<!---弹出层--->


<!-- 补休内容 -->
<script type="text/javascript">
/**获取选中抽样条件*/
function getAbsCheckBox(){
	return wolf.checkValue("abs_checkbox1", true);
}
function isDateNotNull(d1,d2){
	if(wolf.isNotNull(d1) && wolf.isNotNull(d2)){
		return true;
	}else if(wolf.isNull(d1) && wolf.isNull(d2)){
		return true;
	}else{
		return false;
	}
}
</script>

</body>
</html>
